package cn.appsys.service.developer;

import cn.appsys.dao.appinfo.AppInfoMapper;
import cn.appsys.dao.appversion.AppVersionMapper;
import cn.appsys.pojo.AppVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class AppVersionServiceImpl implements AppVersionService {

    @Autowired
    private AppVersionMapper appVersionMapper;

    @Autowired
    private AppInfoMapper appInfoMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<AppVersion> getAppVersionList(Integer appId) {
        return appVersionMapper.getAppVersionList(appId);
    }

    @Override
    public boolean addAppVersion(AppVersion appVersion) {
        if (appVersionMapper.addAppVersion(appVersion)==1){
            if (appInfoMapper.updateVersionId(appVersion.getId(),appVersion.getAppId())==1){
                return true;
            }
        }
        return false;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public AppVersion getAppVersionById(Integer id) {
        return appVersionMapper.getAppVersionById(id);
    }

    @Override
    public boolean updateAppVersion(AppVersion appVersion) {
        if (appVersionMapper.updateAppVersion(appVersion)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteApkFile(Integer id) {
        if (appVersionMapper.deleteApkFile(id)==1){
            return true;
        }
        return false;
    }
}
